<template>
  <div class="login">
    <div class="icon-content">
      <img src="../assets/images/icon.png" alt="" class="icon" />
    </div>
    <div class="desc-content">智能体征监测云服务,让健康自己说话</div>
    <div class="login-content">
      <ul class="content">
        <li class="field-item">
          <van-field
            v-model="user.phone"
            type="number"
            label="手机号码"
            placeholder="请输入手机号码"
          />
        </li>
        <li class="field-item">
          <van-field
            v-model="user.password"
            type="password"
            label="密码"
            placeholder="请输入密码"
          />
        </li>
      </ul>
    </div>
    <button class="login-btn" @click="submit">登录</button>
    <div class="copyright">
      <span> @2023</span>
      <span class="text">陕西大秦盛业科技有限责任公司</span>
      <span>版权所有</span>
    </div>
  </div>
</template>

<script>
import { Login } from "../api/index";

export default {
  data() {
    return {
      input: "",
      index: 0,
      user: {
        phone: "",
        password: "",
      },
    };
  },
  methods: {
    async submit() {
      if (this.user.phone == "") {
        this.$notify({ type: "danger", message: "请输入手机号" });
      } else if (this.user.password == "") {
        this.$notify({ type: "danger", message: "请输入密码" });
      } else {

        var token = this.$route.query.token;
        this.user.token = token;
        var obj = await Login(this.user);
        if (obj.status == 200) {
          localStorage.setItem("token", obj.data);
          this.$dialog.alert({
            message: obj.message,
          });
          setTimeout(() => {
            this.$router.push("/home");
          }, 500);
        } else {
          this.$dialog.alert({
            message: obj.message,
          });
        }
      }
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  width: 750px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .icon-content {
    width: 750px;
    display: flex;
    justify-content: center;
    align-items: center;

    .icon {
      width: 360px;
      height: 340px;
    }
  }

  .desc-content {
    color: #038039;
    font-weight: bold;
    font-size: 30px;
    text-align: center;
    margin-top: 30px;
    margin-bottom: 50px;
  }

  .login-content {
    border: 3px solid #b1b1b1;
    border-radius: 20px;
    width: 710px;
    height: 185px;
    margin-top: 50px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    box-sizing: border-box;

    /deep/.van-cell,
    .van-field {
      background-color: transparent;
    }

    .field-item:nth-child(1) {
      border-bottom: 3px solid #b1b1b1;
      padding-bottom: 5px;
    }
  }

  .login-btn {
    background-color: #006c30;
    color: #fff;
    font-size: 33px;
    font-weight: bold;
    display: flex;
    align-items: center;
    width: 710px;
    height: 110px;
    margin-top: 50px;
    border-radius: 16px;
    justify-content: center;
  }

  .copyright {
    color: #a8a8a8;
    font-size: 20px;
    font-weight: bold;
    margin-top: 60px;

    .text {
      margin: 0 20px;
    }
  }
}
</style>